<template>
<!-- 欠费患者 -->
  <zsearch>
      <template #date>
        <el-date-picker
            class="date-1"
            type="date"
            v-model="date"
            placeholder="选择日期">
        </el-date-picker>
      </template>
      <template #select>
        <el-input class="input-1" v-model="name" placeholder="请输入内容"></el-input>
      </template>
      <template #btns>
        <el-button class="btn-1" @click="hanledSearch">查询</el-button>
			  <el-button class="btn-2">导出</el-button>
      </template>
      <template #table>
        <ztable 
          :tableData='data' 
          :strucs='columns'
          :height="'100%'"
        ></ztable>
        <zpage 
            :currentPage="current" 
            :total="total" 
            @handleSizeChange="handleSizeChange" 
            @handleCurrentChange="handleCurrentChange"
        ></zpage>
      </template>
    </zsearch>
</template>

<script lang='ts'>
import { defineComponent, reactive, toRefs, ref } from '@vue/runtime-core'

import useRequet, { RespData } from "../../hook/network"

import useConfgin from '../../hook/getconfig'

import ztable from '@components/Table/index.vue'
import zpage from '@components/pagination/pagination.vue'
import zsearch from '@components/search/search.vue'

import { ElMessage } from 'element-plus'
const ID = 501
export default defineComponent({
  name: 'PatientsInArrears',
  components: {
    ztable,
    zpage,
    zsearch
  },
  setup() {
    let search = reactive({
      date:'',
      name:'',
      current: 1,
      size: 10,
      total: 0,
    })
    const data = ref([])
    const columns = useConfgin(ID)

    const request = useRequet({ path: "warehouse/inOrder/" });

    const req = () => {
      request.sendRequest({
        address: 'inOrderPage',
        params: search || {},
        success: (resp: RespData) => {
          if(resp.code !== 0) return ElMessage.error(resp.msg || '获取失败')
					data.value = resp.data.records
          search.total = resp.data.total
          search.current = resp.data.current
          console.log(data)
        },
        fail: (resp: RespData) => {
          if(resp.code !== 0) return ElMessage.error(resp.msg || '获取失败')
          
        },
        method: "POST",
      })
    }
    req()
    //搜索
    const hanledSearch = () => {
      req()
    }

    // 分页
    const handleCurrentChange = (val: number) => {
			search.current = val
      req()
			console.log('handleCurrentChange', val)
		}
    const handleSizeChange = (val: number) => {
      search.size = val
      req()
			console.log('handleSizeChange', val)
		}
    return {
      data,
      columns,
      ...toRefs(search),

      handleCurrentChange,
      handleSizeChange,
      hanledSearch
    }
  }
})
</script>

<style>

</style>